package com.gxc.controller;

import com.gxc.entity.User;
import com.gxc.utils.RestControllerResult;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登陆Controller.
 *
 * @author 宫新程
 * @since 2019/1/14 10:11 AM
 */
@Slf4j
@RestController
public class LoginController {

  /** 登陆. */
  @PostMapping("/login")
  public RestControllerResult<Boolean> login(User user, HttpServletRequest request) {
    request.setAttribute("request", "requestMsg");

    if ("admin".equals(user.getUsername())) {
      if ("123qwe".equals(user.getPassword())) {
        return RestControllerResult.success(true);
      } else {
        return RestControllerResult.error("密码错误！");
      }
    } else {
      return RestControllerResult.error("用户名不存在！");
    }
  }

  /**
   * @param sellerCode 客户8码
   * @param user 入参dto.
   * @return Boolean
   */
  @PostMapping("/save/{sellerCode}")
  public RestControllerResult<Boolean> save(
      @PathVariable String sellerCode, @RequestBody User user) {
    System.out.println(sellerCode);
    System.out.println(user);
    return RestControllerResult.success(true);
  }
}
